package net.huashitong.ssydt.provider.common.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.huashitong.ssydt.common.entity.SsCommonNotice;
import net.huashitong.ssydt.common.entity.vo.SsCommonNoticeQueryVO;
import net.huashitong.ssydt.provider.common.service.SsCommonNoticeService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import net.huashitong.user.results.PaginationResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.11.22
 */
@Api(value = "/common/notice", tags = {"公告管理（后台）"})
@RestController
@RequestMapping("/common/notice")
public class SsCommonNoticeController {
    
    private SsCommonNoticeService ssCommonNoticeService;


    @Autowired
    public SsCommonNoticeController(SsCommonNoticeService ssCommonNoticeService) {
        this.ssCommonNoticeService = ssCommonNoticeService;
    }

    @ApiOperation(value = "分页查询列表", notes = "分页查询列表")
    @GetMapping
    public Result<PaginationResult<SsCommonNotice>> getList(@ModelAttribute SsCommonNoticeQueryVO queryVO) {
        PaginationResult<SsCommonNotice> result = ssCommonNoticeService.paginationQuery(queryVO);
        return ResultUtils.getSuccessResults(result);
    }

    @ApiOperation(value = "查询单条记录", notes = "查询单条记录")
    @GetMapping("/{id}")
    public Result<SsCommonNotice> get(@PathVariable Long id) {
        SsCommonNotice ssExamPaperProduce = ssCommonNoticeService.selectByPrimaryKey(id);
        return ResultUtils.getSuccessResults(ssExamPaperProduce);
    }

    @ApiOperation(value = "新增试卷生产记录", notes = "新增试卷生产记录")
    @PostMapping
    public Result<String> post(@RequestBody SsCommonNotice ssCommonNotice) {
        ssCommonNoticeService.insertSelective(ssCommonNotice);
        return ResultUtils.getSuccessResults();
    }

    @ApiOperation(value = "修改生产记录", notes = "修改生产记录")
    @PutMapping("/{id}")
    public Result<String> put(@PathVariable Long id, @RequestBody SsCommonNotice ssExamPaperProduce) {
        ssExamPaperProduce.setId(id);
        ssCommonNoticeService.updateByPrimaryKeySelective(ssExamPaperProduce);
        return ResultUtils.getSuccessResults();
    }


    @ApiOperation(value = "删除记录", notes = "删除记录")
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable Long id) {
        ssCommonNoticeService.logicalDelete(id);
        return ResultUtils.getSuccessResults();
    }

    @ResponseBody
    @PostMapping("/push-message/{id}")
    public Result<String> postPushMessage(@PathVariable Long id) {
        ssCommonNoticeService.postPushMessage(id);
        return ResultUtils.getSuccessResults();
    }


}
